//
//  ImageProcessing.cpp
//  markerARLib
//
//  Created by CvidKal on 16/4/11.
//  Copyright © 2016年 CvidKal. All rights reserved.
//

#include "ImageProcessing.hpp"



namespace ImageProcessing {
    
    
    
    
    
    //The memory of jacobian should be allocated before.
    //The img should be monochrome.
    void imageGradient(const cv::Mat &img,float *jacobian)
    {
        CV_Assert(img.channels() == 1);
        const int stride = img.size().width;
        auto j = (float(*)[2])jacobian;
        memset(jacobian,0,sizeof(float)*img.size().height*img.size().width*2);
        //compute gx and gy for all pixels except border pixels
        for (int y=1; y<img.size().height-1; ++y) {
            auto p = img.ptr<uchar>(y);
            auto jj = j+y*stride;
            for (int x=1; x<stride-1; ++x) {
                auto up = p-stride;
                auto down = p+stride;
                auto left = p-1;
                auto right = p+1;
                jj[x][0] = (right-left)/2;
                jj[x][1] = (up-down)/2;
            }
        }
        
    }
    
    
    
    
}